package com.ls.herostory.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.*;

/**
 * @author liangsu
 * @version v1.0
 * @Description
 * @Date 2020/10/13 10:26
 * @since
 */
public final class MainMsgProcessor {
    private final static Logger logger = LoggerFactory.getLogger(MainMsgProcessor.class);

    private static MainMsgProcessor mainMsgProcessor = new MainMsgProcessor();

    /**
     * 只有一个线程的线程池
     */
    private ThreadPoolExecutor executor;

    private MainMsgProcessor(){
        executor = new ThreadPoolExecutor(1, 1,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(), new MyThreadFactory("MainMsgProcessor"));
    }

    public static MainMsgProcessor getIntance(){
        return mainMsgProcessor;
    }

    public void process(Runnable r){
        // 单线程执行
        executor.submit(r);
    }



}
